package cn.project.sevlet;

import cn.project.dao.UserDao;
import cn.project.model.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/userServlet")
public class UserServlet extends HttpServlet {

/*    @Resource
    private UserDao userDao;*/

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        List<User>list=ac.getBean("userDao",UserDao.class).getAllUser();
        for (User u:list) {
            System.out.println(u.getUserid()+","+u.getUsername());
        }
    }

}
